home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / ctutor2.zip / LOTTYPES.C < prev    next >
C/C++ Source or Header  |  1987-07-04  |  2KB  |  44 lines

  1.                                          /* Chapter 4 - Program 3 */
  2. main()
  3. {
  4. int a;              /* simple integer type                  */
  5. long int b;         /* long integer type                    */
  6. short int c;        /* short integer type                   */
  7. unsigned int d;     /* unsigned integer type                */
  8. char e;             /* character type                       */
  9. float f;            /* floating point type                  */
  10. double g;           /* double precision floating point      */
  11.  
  12.    a = 1023;
  13.    b = 2222;
  14.    c = 123;
  15.    d = 1234;
  16.    e = 'X';
  17.    f = 3.14159;
  18.    g = 3.1415926535898;
  19.  
  20.    printf("a = %d\n",a);      /* decimal output             */
  21.    printf("a = %o\n",a);      /* octal output               */
  22.    printf("a = %x\n",a);      /* hexadecimal output         */
  23.    printf("b = %ld\n",b);     /* decimal long output        */
  24.    printf("c = %d\n",c);      /* decimal short output       */
  25.    printf("d = %u\n",d);      /* unsigned output            */
  26.    printf("e = %c\n",e);      /* character output           */
  27.    printf("f = %f\n",f);      /* floating output            */
  28.    printf("g = %f\n",g);      /* double float output        */
  29.    printf("\n");
  30.    printf("a = %d\n",a);      /* simple int output          */
  31.    printf("a = %7d\n",a);     /* use a field width of 7     */
  32.    printf("a = %-7d\n",a);    /* left justify in field of 7 */
  33.    c = 5;
  34.    d = 8;
  35.    printf("a = %*d\n",c,a);   /* use a field width of 5     */
  36.    printf("a = %*d\n",d,a);   /* use a field width of 8     */
  37.    printf("\n");
  38.    printf("f = %f\n",f);      /* simple float output        */
  39.    printf("f = %12f\n",f);    /* use field width of 12      */
  40.    printf("f = %12.3f\n",f);  /* use 3 decimal places       */
  41.    printf("f = %12.5f\n",f);  /* use 5 decimal places       */
  42.    printf("f = %-12.5f\n",f); /* left justify in field      */
  43. }
  44.